<!doctype html>
<!--suppress ALL -->
<html lang="en" xmlns:th="http://www.thymeleaf.org">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

        <!-- Bootstrap CSS -->
        <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.4.1/dist/css/bootstrap.min.css"/>
        <!-- 图标 -->
        <link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/font-awesome/5.13.0/css/all.css">
        <link rel="stylesheet" th:href="@{/css/common.css}" href="../static/css/common.css">
        <title>用户登录</title>
        <style>
            body {
                font-family: sans-serif;
                background-image: url("/img/im_bg.jpg");
                background-position: center;
                background-size: cover;
            }

            a {
                text-decoration: none;
            }

            .sign-in-form {
                width: 400px;
                box-shadow: 0 0 3px 0 rgba(0, 0, 0, 0.3);
                background: #fff;
                padding: 30px;
                margin: 8% auto 0;
                text-align: center;
            }

            .sign-in-form h1 {
                color: #1c8adb;
                margin-bottom: 30px;
            }

            .input-box {
                border-radius: 20px;
                padding: 10px;
                margin: 10px 0;
                width: 100%;
                border: 1px solid #999;
                outline: none;
            }

            .sign-in-btn, .sign-in-qq-btn {
                color: #fff;
                width: 100px;
                padding: 10px;
                border-radius: 20px;
                font-size: 15px;
                margin: 10px 0;
                border: none;
                outline: none;
                cursor: pointer;
            }

            .sign-in-qq-btn {
                background-color: #21afde;
            }

            img {
                width: 80px;
                margin-top: -80px;
            }
        </style>
    </head>
    <body>
        <div class="container">
            <div class="row">
                <div class="sign-in-form">
                    <img src="../static/img/im_user.png" th:src="@{/img/im_user.png}">
                    <h1>用户登录</h1>
                    <input type="text" class="input-box" placeholder="USERNAME" id="userNickName">
                    <input type="password" class="input-box" placeholder="PASSWORD" id="userPassword">
                    <a th:href="@{/}" class="sign-in-qq-btn btn btn-primary d-inline-block mx-2">返回首页</a>
                    <button class="sign-in-btn btn btn-primary d-inline-block mx-2" onclick="doLogin()">登录
                    </button>
                    <p class="mt-2">
                        没有账号？
                        <a href="#" th:href="@{/user/register}">去注册</a>
                    </p>
                </div>
            </div>
        </div>

        <script src='https://cdn.jsdelivr.net/npm/jquery@3.4.1/dist/jquery.min.js'></script>
        <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js"></script>
        <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.4.1/dist/js/bootstrap.min.js"></script>
        <script th:src="@{/js/bootstrapQ.js}" src='../static/js/bootstrapQ.js'></script>
        <script th:inline="javascript">
            // 用户登录
            function doLogin() {
                let req = {};
                req.userNickName = $('#userNickName').val().trim();
                req.userPassword = $('#userPassword').val().trim();

                if (req.userNickName === '') {
                    bootstrapQ.msg({msg: '请输入用户名', type: 'warning', time: 3000});
                    return;
                }

                if (req.userPassword === '') {
                    bootstrapQ.msg({msg: '请输入密码', type: 'warning', time: 3000});
                    return;
                }

                $.ajax({
                    url: /*[[@{/user/login.do}]]*/'',
                    method: 'POST',
                    data: JSON.stringify(req),
                    dataType: 'json',
                    contentType: 'application/json;charset=utf-8',
                    processData: false,
                    success: (response) => {
                        if (response.success) {
                            location.href = /*[[@{/}]]*/'';
                        } else {
                            bootstrapQ.msg({msg: response.message, type: 'warning', time: 3000});
                            $('#userPassword').val('');
                        }
                    },
                    error: (error) => {
                        bootstrapQ.msg({msg: '网络异常 => ' + error, type: 'danger', time: 3000});
                    }
                });
            }
        </script>
    </body>
</html>